﻿namespace Access.BenhNhan
{
    using ConfigDatabase.Class;
    using Npgsql;
    using Access;
    using BaseClass.Chung;
    using System;

    public class BNThongSo
    {
        private ConnectDatabase _condata;
        private NpgsqlConnection _conn;
        private dtoDSThongSo _dtots;
        private int _idthongso;
        private General _xuli;

        public BNThongSo()
        {
            this._idthongso = 15;
            this._condata = new ConnectDatabase();
            this._dtots = new dtoDSThongSo(this._condata);
            this._xuli = new General(this._condata);
        }

        public BNThongSo(ConnectDatabase condata)
        {
            this._idthongso = 15;
            this._condata = condata;
            this._dtots = new dtoDSThongSo(this._condata);
            this._xuli = new General(this._condata);
        }

        private string f_GetThongSo(int stt, string ten, string giatri1, string giatri2)
        {
            this._dtots.ID = this._idthongso;
            this._dtots.STT = stt;
            this._dtots.TEN = ten;
            this._dtots.GIATRI2 = giatri2;
            this._dtots.GIATRI1 = giatri1;
            this._dtots.Load();
            try
            {
                return this._dtots.GIATRI1;
            }
            catch
            {
                return "";
            }
        }

        private void f_SetThongSo(int stt, string ten, string giatri1, string giatri2)
        {
            this._dtots.ID = this._idthongso;
            this._dtots.STT = stt;
            this._dtots.TEN = ten;
            this._dtots.GIATRI1 = giatri1;
            this._dtots.GIATRI2 = giatri2;
            if (!this._dtots.Update())
            {
                this._dtots.Insert();
            }
        }

        public bool pKB_A1_CapToaNgoaiVien(int iddangnhap)
        {
            try
            {
                return (this.f_GetThongSo(enSTT.kb_captoangoaivien.GetHashCode(), enSTT.kb_captoangoaivien.ToString(), "", iddangnhap.ToString()) == "1");
            }
            catch
            {
                return false;
            }
        }

        public void pKB_A1_CapToaNgoaiVien_set(string giatri, int iddangnhap)
        {
            try
            {
                this.f_SetThongSo(enSTT.kb_captoangoaivien.GetHashCode(), enSTT.kb_captoangoaivien.ToString(), giatri, iddangnhap.ToString());
            }
            catch
            {
            }
        }

        public bool pKB_A2_CapToaNoiVien(int iddangnhap)
        {
            try
            {
                return (this.f_GetThongSo(enSTT.kb_captoanoivien.GetHashCode(), enSTT.kb_captoanoivien.ToString(), "", iddangnhap.ToString()) == "1");
            }
            catch
            {
                return false;
            }
        }

        public void pKB_A2_CapToaNoiVien_set(string giatri, int iddangnhap)
        {
            try
            {
                this.f_SetThongSo(enSTT.kb_captoanoivien.GetHashCode(), enSTT.kb_captoanoivien.ToString(), giatri, iddangnhap.ToString());
            }
            catch
            {
            }
        }

        private enum enSTT
        {
            kb_captoangoaivien = 1,
            kb_captoanoivien = 2
        }
    }
}

